<style lang="less">
</style>

<template>
    <div>
        <Card shadow>
            <iview-table
                ref="table"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                v-on="{changeTotalSize:changeTotalSize,events:events,changeSelect:changeSelect}">
            </iview-table>
            <br>
            <iview-page 
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber" 
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
            </iview-page>
        </Card>
    </div>
</template>

<script>
import iviewTable from '@/view/common/table/Table.vue';
import iviewPage from '@/view/common/page/Page.vue';
export default {
    name: 'text-editor',
    components: {
        iviewTable,
        iviewPage
    },
    data () {
        return {
            selectRows: [],
            queryModel: {
                // 网关代理路径(必须)+资源路径(可选)
                baseURL: '/user'
            },
            dataModel: {
                menuId: 110,
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },{
                        title: '登录用户名',
                        key: 'userLoginName'
                    },{
                        title: '用户名',
                        key: 'username'
                    },{
                        title: '职务',
                        key: 'job',
                        render: (h, params) => {
                            let temp = params.row.job
                            if (temp === 1) {
                                temp = '医生'
                            } else if (temp === 2) {
                                temp = '护士'
                            }
                            return temp
                        }
                    },{
                        title: '是否后勤',
                        key: 'isLogistics',
                        render: (h, params) => {
                            let temp = params.row.isLogistics
                            if (temp === 0) {
                                temp = '否'
                            } else if (temp === 1) {
                                temp = '是'
                            }
                            return temp
                        }
                    }
                ],
                order: 'id desc'
            },
            pageModel: {
                totalSize: 0,
                pageNumber: 1,
                pageSize: 10,
                pageSizeOpts: [10, 50, 100, 500]
            }
        };
    },
    methods: {
        events (item) {
            let path = item.path
            if (path === 'add') {
                this.add()
            } else if (path === 'edit') {
                this.edit()
            } else if (path === 'addRole') {
                this.addRole()
            } else if (path === 'addOrgan') {
                this.addOrgan()
            }
        },
        add () {
            this.$bus.toPath('/user/details')
        },
        edit () {
            if (this.selectRows.length === 1) {
                let row = this.selectRows[0]
                let query = {
                    row: row
                }
                this.$bus.toPath('/user/details', query)
            } else {
                this.$bus.alert('warning', '请选择一条记录')
            }
        },
        addRole () {
            if (this.selectRows.length !== 1) {
                this.$bus.alert('warning', '请选择一条记录', 3)
                this.status = !this.status
                return
            }
            let row = this.selectRows[0]
            let query = {
                id: row.id,
                user: row
            }
            this.$bus.toPath('/user/roleDetails', query)
        },
        addOrgan () {
            if (this.selectRows.length !== 1) {
                this.$bus.alert('warning', '请选择一条记录', 3)
                this.status = !this.status
                return
            }
            let row = this.selectRows[0]
            let query = {
                id: row.id,
                user: row
            }
            this.$bus.toPath('/user/organDetails', query)
        },
        changeSelect (rows) {
            this.selectRows = rows
        },
        changeTotalSize (totalSize) {
            this.pageModel.totalSize = totalSize
        },
        changePageNumber (pageNumber) {
            this.pageModel.pageNumber = pageNumber
        },
        changePageSize (pageSize) {
            this.pageModel.pageSize = pageSize
        },
        refresh () {
            this.$refs.table.refresh()
        },
        init () {
            this.refresh()
        }
    },
    mounted () {
        this.init()
    },
    watch: {
        '$route' (to) {
            if (to.path === '/user') {
                this.init()
            }
        }
    }
};
</script>

<style>

</style>
